# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=koadic
pkgver=3.457f9a3
pkgrel=2
epoch=2
pkgdesc='A Windows post-exploitation rootkit similar to other penetration testing tools such as Meterpreter and Powershell Empire.'
groups=('blackarch' 'blackarch-automation' 'blackarch-exploitation')
arch=('any')
url='https://github.com/offsecginger/koadic'
license=('Apache-2.0')
depends=('impacket' 'python' 'python-legacy-cgi' 'python-pycryptodome'
         'python-pyasn1' 'python-tabulate' 'python-flask' 'python-rjsmin')
makedepends=('git')
source=("git+https://github.com/offsecginger/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  git submodule update --init --recursive
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" DEFCON25.pdf README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm DEFCON25.pdf LICENSE README.md

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python $pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

